package com.ruoyi.teach.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.teach.domain.TeacherLeave;
import com.ruoyi.teach.service.ITeacherLeaveService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 请假管理Controller
 *
 * @author ruoyi
 * @date 2023-11-23
 */
@RestController
@RequestMapping("/teach/leave")
public class TeacherLeaveController extends BaseController
{
    @Autowired
    private ITeacherLeaveService teacherLeaveService;

    /**
     * 查询请假管理列表
     */
    @PreAuthorize("@ss.hasPermi('teach:leave:list')")
    @GetMapping("/list")
    public TableDataInfo list(TeacherLeave teacherLeave)
    {
        startPage();
        List<TeacherLeave> list = teacherLeaveService.selectTeacherLeaveList(teacherLeave);
        return getDataTable(list);
    }

    /**
     * 导出请假管理列表
     */
    @PreAuthorize("@ss.hasPermi('teach:leave:export')")
    @Log(title = "请假管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TeacherLeave teacherLeave)
    {
        List<TeacherLeave> list = teacherLeaveService.selectTeacherLeaveList(teacherLeave);
        ExcelUtil<TeacherLeave> util = new ExcelUtil<TeacherLeave>(TeacherLeave.class);
        util.exportExcel(response, list, "请假管理数据");
    }

    /**
     * 获取请假管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('teach:leave:query')")
    @GetMapping(value = "/{leaveId}")
    public AjaxResult getInfo(@PathVariable("leaveId") Long leaveId)
    {
        return success(teacherLeaveService.selectTeacherLeaveByLeaveId(leaveId));
    }

    /**
     * 新增请假管理
     */
    @PreAuthorize("@ss.hasPermi('teach:leave:add')")
    @Log(title = "请假管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TeacherLeave teacherLeave)
    {
        return toAjax(teacherLeaveService.insertTeacherLeave(teacherLeave));
    }

    /**
     * 修改请假管理
     */
    @PreAuthorize("@ss.hasPermi('teach:leave:edit')")
    @Log(title = "请假管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TeacherLeave teacherLeave)
    {
        return toAjax(teacherLeaveService.updateTeacherLeave(teacherLeave));
    }

    /**
     * 删除请假管理
     */
    @PreAuthorize("@ss.hasPermi('teach:leave:remove')")
    @Log(title = "请假管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{leaveIds}")
    public AjaxResult remove(@PathVariable Long[] leaveIds)
    {
        return toAjax(teacherLeaveService.deleteTeacherLeaveByLeaveIds(leaveIds));
    }
}
